package day7;

import java.util.Scanner;

public class BankAccount {
    String account;
    String password ;
    double money;

    public void addMoney(double money) throws InterruptedException {
        System.out.println(account+"开始存款！");
        for (int i=0;i<3;i++){
            Thread.sleep(1000);
            System.out.println("存款中..."+(3-i)+"秒");
        }
        this.money+=money;
        System.out.println(account+"存款成功！");
    }

    public void minusMoney(double money) throws InterruptedException {
        System.out.println(account+"开始取款！");
        for (int i=0;i<3;i++){
            Thread.sleep(1000);
            System.out.println("取款中..."+(3-i)+"秒");
        }
        this.money-=money;
        System.out.println(account+"取款成功！");
    }

    public double getMoney() {
        System.out.println(account+"当前的余额为："+money+"元");
        return money;

    }

    public BankAccount(String account,String password,double money){
        this.account=account;
        this.password=password;
        this.money=money;
    }

}
class TestBank {
    static Scanner sc = new Scanner(System.in);
    static BankAccount ba = new BankAccount("admin","123456",10000);
    public static void main(String[] args) throws InterruptedException {
        once();
        System.out.println("退出系统！");
    }


    public static void once() throws InterruptedException {
        System.out.println("******登录功能******");
        System.out.println("1.登录");
        System.out.println("2.退出");
        System.out.println("******************");
        System.out.print("请输入编号：");
        int num = sc.nextInt();
        while (true) {
            switch (num) {
                case 1:
                    login();
                case 2:
                    return;
            }
        }
    }

    public static void second() throws InterruptedException {
        while (true){
        System.out.println("****" + ba.account + "登录成功*****");
        System.out.println("1.存款");
        System.out.println("2.取款");
        System.out.println("3.查询余额");
        System.out.println("4.退出登录");
        System.out.println("**************************");
        System.out.print("请输入编号：");
        int nums = sc.nextInt();
        switch (nums) {
            case 1:
                add();
                break;
            case 2:
                minus();
                break;
            case 3:
                ba.getMoney();
                break;
            case 4:
                once();
                return;
        }
        }
    }
    public static void login() throws InterruptedException {
        for (int i = 0; i < 3; i++) {
        System.out.print("请输入账户：");
        String username = sc.next();
        System.out.print("请输入密码：");
        String password = sc.next();
        if (username.equals(ba.account) || password.equals(ba.password)) {
            System.out.println("登录成功");
            second();
            return;
        } else if (i == 2) {
            System.out.println("连续三次登录失败，账号锁定！");
            System.exit(0);
        } else {
            System.out.println("账号或密码错误，请重新输入！");
        }
    }
    }
    public static void add() throws InterruptedException {
        System.out.println("开始存钱");
        System.out.print("请输入存款金额：");
        int money=sc.nextInt();
        ba.addMoney(money);
    }

    public static void minus() throws InterruptedException {
        System.out.println("开始取款");
        System.out.print("请输入取款金额：");
        int money=sc.nextInt();
        if (money>ba.money){
            System.out.println("余额不足！！！");
            return;
        }
        ba.minusMoney(money);
    }
}

